(function(){if(window.JCClock)return;function i(i){if(typeof BX!="undefined")BX.onCustomEvent("onJCClockInit",[i]);this.config=i;this.config.AmPmMode=BX.isAmPmMode();this.config.AmPm="";this.deltaHour=0;this.MESS=this.config.MESS;this.bCreated=false;this.DATE_FORMAT=BX.date.convertBitrixFormat(BX.message("FORMAT_DATE"))}i.prototype={Create:function(i){this.bCreated=true;this.pInput=document.getElementById(this.config.inputId);this.pIcon=document.getElementById(this.config.iconId);if(i&&(i=document.getElementById(i))){this.bInline=true;this.oDiv=i;this.oDiv.className="bx-clock-div bx-clock-div-inline"+(this.config.AmPmMode?"_am_pm":"");this.oDiv.style.position="relative"}else{var t=150;if(typeof this.config["zIndex"]!="undefined"){t=parseInt(this.config["zIndex"]);if(t<=0)t=150}this.oDiv=BX(this.config.inputId+"_div");if(this.oDiv)BX.cleanNode(this.oDiv,true);this.oDiv=BX.create("DIV",{props:{className:"bx-clock-div",id:this.config.inputId+"_div"},style:{zIndex:t}});document.body.appendChild(this.oDiv)}var e=BX.create("DIV",{props:{className:"bxc-clock-cont bxc-iconkit-c"}});this.arrowsContDiv=BX.create("DIV",{props:{className:"bxc-arrows-cont h0 m0"}});this.MACDiv=this.arrowsContDiv.appendChild(BX.create("DIV",{props:{className:"bxc-mouse-control-cont"}}));this.arrowsContDiv.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"bxc-min-arr-cont bxc-iconkit-a"}}));this.arrowsContDiv.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"bxc-hour-arr-cont bxc-iconkit-a"}}));e.appendChild(this.arrowsContDiv);this.oDiv.appendChild(e);this.CreateControls();this.InitMouseArrowControl()},CreateControls:function(){this.ControlsCont=BX.create("DIV",{props:{className:"bxc-controls-cont"}});var i,t=[],e=[],n=this;if(this.config.AmPmMode){for(i=0;i<12;i++)t.push(this.Hour2Str(i,true))}else{for(i=0;i<24;i++)t.push(this.Int2Str(i))}for(i=0;i<60;i+=this.config.step)e[i]=this.Int2Str(i);var s=this.CreateSelect(t,1,this.MESS.Hours);this.hourSelect=s.pSelect;var o=this.CreateSelect(e,this.config.step,this.MESS.Minutes);this.minSelect=o.pSelect;this.hourSelect.onchange=function(){if(!this.value||isNaN(this.value))this.value=0;n.SetTime(this.value,n.curMin,true)};this.minSelect.onchange=function(){if(!this.value||isNaN(this.value))this.value=0;n.SetTime(n.curHour,this.value,true)};this.minSelect.onfocus=function(){n.lastArrow="min"};this.hourSelect.onfocus=function(){n.lastArrow="hour"};if(!this.bInline){var r=BX.create("INPUT",{props:{type:"button",value:this.MESS.Insert}});r.onclick=function(){n.Submit()};var a=BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"bxc-close bxc-iconkit-c",title:this.MESS.Close}});a.onclick=function(){n.Close()}}var h=BX.create("SPAN",{props:{className:"double-dot"}});h.innerHTML=":";s.pWnd.style.marginLeft="11px";this.ControlsCont.appendChild(s.pWnd);this.ControlsCont.appendChild(h);this.ControlsCont.appendChild(o.pWnd);if(this.config.AmPmMode){this.AmPm=BX.create("SPAN",{props:{className:"bxc-am-pm",title:"a.m."}});this.AmPm.innerHTML="am";this.AmPm.onclick=function(){if(this.title=="a.m."){this.title="p.m.";this.innerHTML="pm";n.config.AmPm=" pm"}else{this.title="a.m.";this.innerHTML="am";n.config.AmPm=" am"}n.SetTime(n.curHour,n.curMin,true)};this.ControlsCont.appendChild(this.AmPm)}if(!this.bInline){this.ControlsCont.appendChild(r);this.ControlsCont.appendChild(a);this.pTitle=this.ControlsCont.appendChild(BX.create("DIV",{props:{className:"bxc-title"}}));this.pTitle.onmousedown=function(i){jsFloatDiv.StartDrag(i,n.oDiv);n.bRecalculateCoordinates=true}}this.oDiv.appendChild(this.ControlsCont)},CalculateCoordinates:function(){var t=BX.pos(this.oDiv);this.top=t.top;this.left=t.left;this.centerX=t.left+(this.bInline?i.getOption("centerXInline",55):i.getOption("centerX",55));this.centerY=t.top+(this.bInline?i.getOption("centerYInline",55):i.getOption("centerY",71));var e=this,n=i.getOption("minuteLength",32),s=i.getOption("hourLength",25),o=this.centerX,r=this.centerY,a,h,c,l,u,f,m,d,p,M,C=i.getOption("inaccuracy",8);this.arHourCoords=[];this.bJumpByMinArrow30=false;for(a=0;a<12;a++){h=a*30*Math.PI/180;c=Math.round(s*Math.sin(h));l=Math.round(s*Math.cos(h));u=o+c;f=r-l;m=Math.round(16*Math.sin(h));d=Math.round(16*Math.cos(h));p=o+m;M=r-d;this.arHourCoords[a]={x:u,y:f,x_min:u-C,x_max:u+C,y_min:f-C,y_max:f+C,x_min1:p-C,x_max1:p+C,y_min1:M-C,y_max1:M+C}}this.arMinCoords={};for(a=0;a<12;a++){h=a*30*Math.PI/180;c=Math.round(n*Math.sin(h));l=Math.round(n*Math.cos(h));u=o+c;f=r-l;m=Math.round(18*Math.sin(h));d=Math.round(18*Math.cos(h));p=o+m;M=r-d;this.arMinCoords[a*5]={x:u,y:f,x_min:u-C,x_max:u+C,y_min:f-C,y_max:f+C,x_min1:p-C,x_max1:p+C,y_min1:M-C,y_max1:M+C}}this.bRecalculateCoordinates=false},Show:function(i){if(!this.bCreated)this.Create(i);this.lastArrow="min";var t=this.pInput.value.toString();if(t.indexOf(":")==-1){if(this.config.initTime.length<=0||this.config.initTime.indexOf(":")==-1)t=(new Date).getHours()+":"+(new Date).getMinutes();else t=this.config.initTime}t=this.parseTime(t);this.SetTime(t.h,t.m);if(this.bInline){this.oDiv.style.display="block"}else{var e=this.pIcon||this.pInput;var n=this.AlignToPos(BX.pos(e));this.top=n.top;this.left=n.left;jsFloatDiv.Show(this.oDiv,this.left,this.top);this.oDiv.style.display="block";jsFloatDiv.AdjustShadow(this.oDiv)}var s=this;setTimeout(function(){s.CalculateCoordinates()},20);window["_bxc_onmousedown"+this.config.inputId]=function(i){s.CheckClick(i)};window["_bxc_onkeypress"+this.config.inputId]=function(i){s.OnKeyDown(i)};setTimeout(function(){BX.bind(document,"mousedown",window["_bxc_onmousedown"+s.config.inputId])},10);BX.bind(document,"keypress",window["_bxc_onkeypress"+this.config.inputId])},AlignToPos:function(t){var e=i.getOption("popupHeight",250),n=t.left,s=t.top-e,o=BX.GetWindowScrollPos();if(o.scrollTop>s||s<0)s=t.top+40;return{left:n,top:s}},Close:function(){if(this.bInline)return;BX.unbind(document,"mousedown",window["_bxc_onmousedown"+this.config.inputId]);BX.unbind(document,"keypress",window["_bxc_onkeypress"+this.config.inputId]);jsFloatDiv.Close(this.oDiv);this.oDiv.style.display="none"},Submit:function(){var i=this.config.AmPmMode?this.config.AmPm:"";this.pInput.value=this.Hour2Str(this.curHour,this.config.AmPmMode)+":"+this.Int2Str(this.curMin)+i;BX.fireEvent(this.pInput,"change");if(!this.bInline)this.Close()},SetTime:function(i,t,e,n){i=parseInt(i,10);if(this.config.AmPmMode){if(i>=12){if(i>12)i=i-12;if(this.config.AmPm=="")this.config.AmPm=" pm"}else if(this.config.AmPm==""){this.config.AmPm=" am"}if(i<1||i>12){i=12;this.config.AmPm=" am"}}else if(i<0||i>23)i=0;t=parseInt(t,10);var s=this.config.step;if(Math.round(t/s)!=t/s)t=Math.round(t/s)*s;if(t<0||t>59)t=0;if(!n)this.deltaHour=i>=12?12:0;this.curMin=t;this.curHour=i;if(this.pTitle)this.pTitle.innerHTML=this.Hour2Str(i,this.config.AmPmMode)+":"+this.Int2Str(t);this.SetTimeAn(i,t);if(!e)this.SetTimeDig(i,t);if(this.bInline)this.Submit()},SetTimeAnH:function(i,t){if(i==0){if(this.curHour<12&&this.curHour>6)this.deltaHour=12;if(this.curHour<24&&this.curHour>18)this.deltaHour=0}if(this.curHour==0&&i==11){i=23;this.deltaHour=12}else if(this.curHour==12&&i==11){i=11;this.deltaHour=0}else{i+=this.deltaHour}this.SetTime(i,t,false,true)},SetTimeAnM:function(i,t){t=parseInt(t,10);var e=this.config.step;if(Math.round(t/e)!=t/e)t=Math.round(t/e)*e;if(t<0||t>59)t=0;if(t==30){this.bJumpByMinArrow30=true}else if(this.bJumpByMinArrow30&&t==0){if(this.curMin>30&&this.curMin<59){this.bJumpByMinArrow30=false;this.SetTime(++i,t);return}if(this.curMin>0&&this.curMin<30){this.bJumpByMinArrow30=false;if(i==0)i=24;this.SetTime(--i,t);return}}this.SetTime(i,t)},SetTimeAn:function(i,t){i=parseInt(i,10);if(isNaN(i))i=0;t=parseInt(t,10);if(isNaN(t))t=0;if(i>=12)i-=12;var e="bxc-arrows-cont";if(i*5==t)e+=" hideh hm"+i;else e+=" h"+i+" m"+t;this.arrowsContDiv.className=e},CreateSelect:function(i,t,e){var n=!!this.config.AmPmMode;var s=BX.create("INPUT",{props:{type:"text",className:"bxc-cus-sel",size:"1",title:e}});var o=function(i){s._bxmousedown=false;if(window.bxinterval)clearTimeout(window.bxinterval)};var r=function(t){if(!s._bxmousedown){o();return}var e=parseInt(s.value,10);if(isNaN(e))e=0;e=e+t;if(e>=i.length)e=0;else if(e<0)e=i.length-1;if(typeof i[e]=="undefined"){e-=t;s.value=e-(t>0?1:-1);r(t);return}else{if(s.value=="11"&&i[e]=="00"||s.value=="01"&&i[e]=="00"&&n){s.value="12"}else if(s.value=="12"&&i[e]=="00"){s.value="01"}else s.value=i[e];s.onchange()}if(window.bxinterval)clearTimeout(window.bxinterval);window.bxinterval=setTimeout(function(){r(t)},100)};var a=function(i){if(window.bxinterval)o();s._bxmousedown=true;BX.bind(document,"mouseup",o);r(i);if(window.bxinterval)clearTimeout(window.bxinterval);window.bxinterval=setTimeout(function(){r(i)},800)};s.onkeydown=function(i){if(!i)i=window.event;if(!i)return;if(i.keyCode==38){a(t);o()}else if(i.keyCode==40){a(-t);o()}};var h=BX.create("TABLE",{props:{className:"bxc-cus-sel-tbl"}}),c=h.insertRow(-1),l=c.insertCell(-1);l.rowSpan=2;l.appendChild(s);l=c.insertCell(-1);l.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"bxc-slide-up bxc-iconkit-c"}}));l.title=this.MESS.Up;l.className="bxc-pointer";l.onmousedown=function(){a(t)};l=h.insertRow(-1).insertCell(-1);l.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"bxc-slide-down bxc-iconkit-c"}}));l.title=this.MESS.Down;l.className="bxc-pointer";l.onmousedown=function(){a(-t)};return{pSelect:s,pWnd:h}},SetTimeDig:function(i,t){this.hourSelect.value=this.Hour2Str(i,this.config.AmPmMode);this.minSelect.value=this.Int2Str(t);if(this.config.AmPmMode){if(this.config.AmPm==" pm"){this.AmPm.title="p.m.";this.AmPm.innerHTML="pm"}else{this.AmPm.title="a.m.";this.AmPm.innerHTML="am"}}if(this.bInline)this.Submit()},InitMouseArrowControl:function(){var i=this;this.MACDiv.onmousedown=function(t){i.MACMouseDown(t)};this.MACDiv.ondrag=BX.False;this.MACDiv.onselectstart=BX.False;this.MACDiv.style.MozUserSelect="none"},MACMouseDown:function(i){if(this.bRecalculateCoordinates)this.CalculateCoordinates();if(!i)i=window.event;var t=this,e,n=BX.GetWindowSize(),s=i.clientX+n.scrollLeft,o=i.clientY+n.scrollTop;this.ddMode=false;e=this.arMinCoords[this.curMin];if(s>e.x_min&&s<e.x_max&&o>e.y_min&&o<e.y_max||s>e.x_min1&&s<e.x_max1&&o>e.y_min1&&o<e.y_max1){this.ddMode="min";this.lastArrow="min"}if(!this.ddMode){e=this.arHourCoords[this.curHour>=12?this.curHour-12:this.curHour];if(s>e.x_min&&s<e.x_max&&o>e.y_min&&o<e.y_max||s>e.x_min1&&s<e.x_max1&&o>e.y_min1&&o<e.y_max1){this.ddMode="hour";this.lastArrow="hour"}}if(this.ddMode===false){var r,a,h=1e3,c=0;if(this.lastArrow=="hour"){for(r=0;r<12;r++){a=this.GetDistance(this.arHourCoords[r].x,this.arHourCoords[r].y,s,o);if(a<=h){h=a;c=r}}this.SetTimeAnH(c,this.curMin)}else if(this.lastArrow=="min"){for(r=0;r<12;r++){a=this.GetDistance(this.arMinCoords[r*5].x,this.arMinCoords[r*5].y,s,o);if(a<=h){h=a;c=r}}this.SetTimeAnM(this.curHour,c*5)}return}this.ControlsCont.style.zIndex="145";this.MACDiv.onmousemove=function(i){t.MACMouseMove(i)};this.MACDiv.onmouseup=function(i){t.MACMouseUp(i)}},MACMouseMove:function(i){if(!this.ddMode){this.StopDD();return}if(!i)i=window.event;var t,e,n=1e3,s=0,o=BX.GetWindowSize(),r=i.clientX+o.scrollLeft,a=i.clientY+o.scrollTop;if(this.ddMode=="hour"){for(t=0;t<12;t++){e=this.GetDistance(this.arHourCoords[t].x,this.arHourCoords[t].y,r,a);if(e<=n){n=e;s=t}}this.SetTimeAnH(s,this.curMin)}else if(this.ddMode=="min"){for(t=0;t<12;t++){e=this.GetDistance(this.arMinCoords[t*5].x,this.arMinCoords[t*5].y,r,a);if(e<=n){n=e;s=t}}this.SetTimeAnM(this.curHour,s*5)}},GetDistance:function(i,t,e,n){return Math.round(Math.sqrt(Math.pow(i-e,2)+Math.pow(t-n,2)))},MACMouseUp:function(i){this.StopDD()},StopDD:function(){this.ddMode=false;this.ControlsCont.style.zIndex="156";this.MACDiv.onmousemove=null;this.MACDiv.onmouseup=null;return false},Int2Str:function(i){i=parseInt(i,10);if(isNaN(i))i=0;return i<10?"0"+i.toString():i.toString()},Hour2Str:function(i,t){i=parseInt(i,10);if(isNaN(i))i=0;return i<10&&!t?"0"+i.toString():i.toString()},CheckClick:function(i){if(this.bRecalculateCoordinates||this.bInline)return;if(!i)i=window.event;if(!i)return;var t;if(i.target)t=i.target;else if(i.srcElement)t=i.srcElement;if(t.nodeType==3)t=t.parentNode;if(t!=this.oDiv&&!BX.findParent(t,{attribute:{id:this.oDiv.id}}))this.Close()},OnKeyDown:function(i){if(!i)i=window.event;if(!i)return;if(i.keyCode==27)this.Close()},parseTime:function(i){var t=this.parseDate(BX.date.format(this.DATE_FORMAT,new Date)+" "+i,false);return t?{h:t.getHours(),m:t.getMinutes()}:t},parseDate:function(i,t,e){var n,s,o,r,a=false;if(!t)t=BX.message("FORMAT_DATETIME");i=BX.util.trim(i);if(e!==false)t=t.replace(":SS","");if(BX.type.isNotEmptyString(i)){r="";for(n=1;n<=12;n++){r=r+"|"+BX.message("MON_"+n)}var h=new RegExp("([0-9]+|[a-z]+"+r+")","ig"),c=i.match(h),l=BX.message("FORMAT_DATE").match(/(DD|MI|MMMM|MM|M|YYYY)/gi),u=[],f=[],m={};if(!c){return null}if(c.length>l.length){l=t.match(/(DD|MI|MMMM|MM|M|YYYY|HH|H|SS|TT|T|GG|G)/gi)}for(n=0,s=c.length;n<s;n++){if(BX.util.trim(c[n])!=""){u[u.length]=c[n]}}for(n=0,s=l.length;n<s;n++){if(BX.util.trim(l[n])!=""){f[f.length]=l[n]}}var d=BX.util.array_search("MMMM",f);if(d>0){u[d]=BX.getNumMonth(u[d]);f[d]="MM"}else{d=BX.util.array_search("M",f);if(d>0){u[d]=BX.getNumMonth(u[d]);f[d]="MM"}}for(n=0,s=f.length;n<s;n++){o=f[n].toUpperCase();m[o]=o=="T"||o=="TT"?u[n]:parseInt(u[n],10)}if(m["DD"]>0&&m["MM"]>0&&m["YYYY"]>0){var p=new Date;if(a){p.setUTCDate(1);p.setUTCFullYear(m["YYYY"]);p.setUTCMonth(m["MM"]-1);p.setUTCDate(m["DD"]);p.setUTCHours(0,0,0)}else{p.setDate(1);p.setFullYear(m["YYYY"]);p.setMonth(m["MM"]-1);p.setDate(m["DD"]);p.setHours(0,0,0)}if((!isNaN(m["HH"])||!isNaN(m["GG"])||!isNaN(m["H"])||!isNaN(m["G"]))&&!isNaN(m["MI"])){if(!isNaN(m["H"])||!isNaN(m["G"])){var M=(m["T"]||m["TT"]||"am").toUpperCase()=="PM";var C=parseInt(m["H"]||m["G"]||0,10);if(M){m["HH"]=C+(C==12?0:12)}else{m["HH"]=C<12?C:0}}else{m["HH"]=parseInt(m["HH"]||m["GG"]||0,10)}if(isNaN(m["SS"]))m["SS"]=0;if(a){p.setUTCHours(m["HH"],m["MI"],m["SS"])}else{p.setHours(m["HH"],m["MI"],m["SS"])}}return p}}return null}};i.options={};i.setOptions=function(t){if(!t||typeof t!="object")return;for(var e in t)i.options[e]=t[e]};i.getOption=function(t,e){if(typeof i.options[t]!="undefined")return i.options[t];else return e};window.JCClock=i})();